fix(sync): stop provider_event_identity collisions on series instance edits - #2748
Merged
Merged
Conversation
Google imports stored instance recurrenceIds as offset ISO strings while commands use Date#toISOString(), so upsertException missed the imported row and collided provider_event_identity. Canonicalize import recurrenceIds and make upsertException adopt the existing provider-identity document. Co-authored-by: Tyler Dane <tyler-dane@users.noreply.github.com>
Canonical UTC recurrenceIds made import collide series_exception_identity with null-provider command tombstones. Reconcile before provider-identity upserts so import adopts or drops the series-keyed row first. Co-authored-by: Tyler Dane <tyler-dane@users.noreply.github.com>
4 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes the PostHog errors where scope-
thiscommand execution (and thestaleCommandRetrysweep retrying those stuck commands) threw MongoE11000oncompass_sync.eventsindexprovider_event_identity.Root cause: Google import wrote series exceptions via
upsertByProviderIdentitywith offset-form recurrenceIds (2026-08-10T13:00:00-06:00), while commands wrote viaupsertExceptionkeyed on the canonical UTC form (2026-08-10T19:00:00.000Z). Same instant, different strings → series filter miss → insert collided with the imported providerEventId (masterId_20260810T190000Z). The failed command stayed nonterminal, sostaleCommandRetrylooped the same error.Fix:
recurrenceIds toDate#toISOString()(matching projection and command paths).upsertExceptionto converge on an existing provider-identity document (and drop a series-keyed duplicate when both exist), including E11000 race recovery.Issues
Test plan
bun test packages/sync/src/providers/google/google-event.normalizer.test.tsbun test:sync -- packages/sync/src/storage/repositories/event.repository.db.test.ts(includes new dual-key / format-mismatch regressions)bun test:sync+bun lintafter PR open